/**
 入驻小区
 **/
(function (vc) {
    var DEFAULT_PAGE = 1;
    var DEFAULT_ROWS = 10;
    vc.extends({
        data: {
            aRoomDetailMeterWaterLogInfo: {
                meterTypes: [],
                meterWaters: [],
                total: 0,
                records: 1,
                roomId: '',
                feeId: '',
                roomName: '',
                ownerName: '',
                floorNum: '',
                unitNum: '',
                roomNum: '',
                meterType: ""
            }
        },
        _initMethod: function () {
        },
        _initEvent: function () {
            //切换 至费用页面
            vc.on('aRoomDetailMeterWaterLog', 'switch', function (_param) {
                if (_param.roomId == '') {
                    return;
                }
                $that.clearARoomDetailMeterWaterLogInfo();
                vc.copyObject(_param, $that.aRoomDetailMeterWaterLogInfo);
                $that._listARoomDetailMeterWaterLog(DEFAULT_PAGE, DEFAULT_ROWS);
            });
            vc.on('aRoomDetailMeterWaterLog', 'paginationPlus', 'page_event',
                function (_currentPage) {
                    $that._listARoomDetailMeterWaterLog(_currentPage, DEFAULT_ROWS);
                });
        },
        methods: {
            _listARoomDetailMeterWaterLog: function (_page, _row) {
                let param = {
                    params: {
                        page: _page,
                        row: _row,
                        objId: $that.aRoomDetailMeterWaterLogInfo.roomId,
                        feeId: $that.aRoomDetailMeterWaterLogInfo.feeId,

                    }
                };
                //发送get请求
                vc.http.apiGet('/meterWater.listAdminMeterWaters',
                    param,
                    function (json) {
                        let _json = JSON.parse(json);
                        $that.aRoomDetailMeterWaterLogInfo.total = _json.total;
                        $that.aRoomDetailMeterWaterLogInfo.records = _json.records;
                        $that.aRoomDetailMeterWaterLogInfo.meterWaters = _json.data;
                        vc.emit('simplifyMeterWaterLog', 'paginationPlus', 'init', {
                            total: $that.aRoomDetailMeterWaterLogInfo.records,
                            dataCount: $that.aRoomDetailMeterWaterLogInfo.total,
                            currentPage: _page
                        });
                    }, function () {
                        console.log('请求失败处理');
                    }
                );
            },
            _openAddMeterWaterModal: function () {
                vc.emit('addMeterWater', 'openAddMeterWaterModal', {
                    roomId: $that.aRoomDetailMeterWaterLogInfo.roomId,
                    roomName: $that.aRoomDetailMeterWaterLogInfo.roomName,
                    ownerName: $that.aRoomDetailMeterWaterLogInfo.ownerName
                });
            },
            clearARoomDetailMeterWaterLogInfo: function () {
                $that.aRoomDetailMeterWaterLogInfo = {
                    meterTypes: [],
                    meterWaters: [],
                    total: 0,
                    records: 1,
                    roomId: '',
                    feeId: '',
                    ownerName: '',
                    roomName: '',
                    floorNum: '',
                    unitNum: '',
                    roomNum: '',
                    meterType: ""
                }
            },
            _getMeteTypeName: function (_meterType) {
                if (_meterType == '1010') {
                    return "电表";
                } else if (_meterType == '2020') {
                    return "水表";
                }
                return "煤气费";
            },
        }
    });
})(window.vc);
